﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework;
using PloobsEngine.Behaviors;
using PloobsEngine.Tasks;

namespace PloobsEngine.Modelo.Animation
{
    public class StopMovimentTask : ITask
    {

        float v;
        bool active = false;
        CharacterMovimentationBehavior cmb;

        public StopMovimentTask(CharacterMovimentationBehavior cmb)
        {            
            this.cmb = cmb;
        }
        #region ITask Members

        public void restart()
        {
           
                v = 1;
                
        }

        public bool Activate
        {
            get
            {
                
                return active;
            }
            set
            {
                lock (this)
                {
                    this.active = value;
                }
            }
        }

        public void Result(IAsyncResult result)
        {
            v = 1;
        }

        public void Process()
        {

            while(!active)
            {
                Thread.Sleep(500);
            }
            
            lock (this)
            {
                v = 1;
                while (v > 0)
                {
                    Thread.Sleep(100);         
                    v = v - 0.05f;
                    cmb.setMultiplier(v);
                    cmb.PerformBehavior(null,null);                    

                }
            }
        }

        #endregion
    }
}
